<?php

namespace App\Models\finance;

use App\Models\AdminModel;
use App\Models\CustomerModel;
use App\Models\service\DataTypeModel;
use App\Models\StaffModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class InvoiceModel extends BaseModel
{
    use HasFactory, SoftDeletes;

    protected $table = 't_finance_invoice';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = null;
    const INVOICE_TYPE_CUSTOMER = 1;
    const INVOICE_TYPE_SUPPLIER = 2;
    const INVOICE_TYPE = [
        self::INVOICE_TYPE_CUSTOMER => '客户',
        self::INVOICE_TYPE_SUPPLIER => '供应商',
    ];

    const TYPE = [1 => '应收', 2 => '应付'];

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];


    //创建人
    public function create_admin(): BelongsTo {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }

    //客户
    public function customer(): BelongsTo {
        return $this->belongsTo(CustomerModel::class, 'customer_id');
    }

    //关联客户或者供应商
    public function invoiceable(): MorphTo {
        return $this->MorphTo();
    }

}
